package com.ruoyi.web.controller.mongo;

import com.ruoyi.mongo.cet4.Entity4;
import com.ruoyi.mongo.cet4.EntityExpand4;
import com.ruoyi.mongo.cet4.EntityTestRecord;
import com.ruoyi.mongo.cet4.repository.SecondaryRepository;
import com.ruoyi.mongo.cet4.service.EntityInterface;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/cet4")
public class Cet4Controller {
    private final SecondaryRepository secondaryRepository;

    private final EntityInterface entityInterface;

    public Cet4Controller(SecondaryRepository secondaryRepository,
                          EntityInterface entityInterface) {
        this.secondaryRepository = secondaryRepository;
        this.entityInterface = entityInterface;
    }

    @GetMapping("/list/{group}")
    public AjaxResult list(@PathVariable int group){
        return AjaxResult.success(secondaryRepository.findByGroup(group));
    }

    @GetMapping("/group")
    public AjaxResult group(@RequestParam(required = false) int group){
        return AjaxResult.success(secondaryRepository.findByGroup(group));
    }

    @GetMapping("/groupData")
    public AjaxResult groupData(@RequestParam int group){
        List<EntityExpand4> list = entityInterface.selectListByGroup(group);
        return AjaxResult.success(list);
    }

    @GetMapping("/groupNotData")
    public AjaxResult groupNotData(@RequestParam int group){
        List<EntityExpand4> list = entityInterface.selectRandomNotGroup(group);
        return AjaxResult.success(list);
    }

    @GetMapping("/practice")
    public AjaxResult practice(@RequestParam(required = false) String practice){
        List<Entity4> list = entityInterface.selectListByPracticeId(practice);
        return AjaxResult.success(list);
    }

    @GetMapping("/testDetails")
    public AjaxResult testDetails(@RequestParam(required = false) String practice){
        List<EntityTestRecord> list = entityInterface.selectTestListByPracticeId(practice);
        return AjaxResult.success(list);
    }

    @GetMapping("/type")
    public AjaxResult type(@RequestParam(required = false) String type){
        List<EntityExpand4> list = entityInterface.selectListByType(type,200);
        return AjaxResult.success(list);
    }

    @GetMapping("/typeRandom")
    public AjaxResult typeRandom(@RequestParam(required = false) String type){
        List<EntityExpand4> list = entityInterface.selectListByTypeRandom(type,100);
        return AjaxResult.success(list);
    }

    @PostMapping("/data")
    public AjaxResult putData(@RequestBody Entity4 entity){
        entityInterface.saveData(entity);
        return AjaxResult.success();
    }

    @PostMapping("/dataList")
    public AjaxResult putDataList(@RequestBody List<Entity4> list){
        entityInterface.saveList(list);
        return AjaxResult.success();
    }

    @PostMapping("/dataTestList")
    public AjaxResult putTestList(@RequestBody List<EntityTestRecord> list){
        entityInterface.saveTestList(list);
        return AjaxResult.success();
    }
}
